﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NH_Factory;
using NH_Entity;
using NHibernate;

namespace PWL_MVC_NH.Controllers
{
    public class HomeController : Controller
    {
        //private static ISessionFactory sessionFactory = NHibernateHelper.CreateSessionFactory();
        public ActionResult Index()
        {
            ////sessionFactory = NHibernateHelper.CreateSessionFactory();
            IEnumerable<QHY_Module> categories;
            using (var session = NHibernateHelper.sessionFactory.OpenSession())
            {
                categories = session.QueryOver<QHY_Module>().List();

               //// QHY_Role role = new QHY_Role();
               //// role.RoleName = "管理员";
               //// role.RoleDescription = "管理员";
               ////var id= session.Save(role);
            }
            


            return View();

        }

        public ActionResult Edit()
        {
            //sessionFactory = NHibernateHelper.CreateSessionFactory();
            QHY_Role role = null;
            using (var session = NHibernateHelper.sessionFactory.OpenSession())
            using (var tx = session.BeginTransaction())
            {

                role = session.Get<QHY_Role>(1);
                role.RoleName = "2222";
                role.RoleDescription = "22222";
                tx.Commit();

            }

            return View();



        }
        public ActionResult Delete()
        {
            using (var session = NHibernateHelper.sessionFactory.OpenSession())
            using (var tx = session.BeginTransaction())
            {
                var productToDelete = session.Load<QHY_Role>(3);
                session.Delete(productToDelete);
                tx.Commit();
            }
            return View();
        }
        public ActionResult About()
        {
            return View();
        }
    }
}
